/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = 'central';
  
  checkConfig(config);
  @endpoint = getEndpoint('cloudauth', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model EntElementVerifyRequest {
  entName?: string(name='EntName'),
  infoVerifyType?: string(name='InfoVerifyType', example='ENT_2META'),
  legalPersonCertNo?: string(name='LegalPersonCertNo', example='370105*****3892'),
  legalPersonName?: string(name='LegalPersonName'),
  licenseNo?: string(name='LicenseNo', example='32132***328932'),
  merchantBizId?: string(name='MerchantBizId', example='32198****193000'),
  merchantUserId?: string(name='MerchantUserId', example='432***421'),
  sceneCode?: string(name='SceneCode', example='withdraw'),
  userAuthorization?: string(name='UserAuthorization', example='1'),
}

model EntElementVerifyResponseBody = {
  code?: string(name='Code', example='Success'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='473469C7***B-A3DC0DE3C83E'),
  result?: {
    bizCode?: string(name='BizCode', example='1'),
    openTime?: string(name='OpenTime'),
    reasonCode?: string(name='ReasonCode'),
    reasonDetail?: string(name='ReasonDetail'),
    status?: string(name='Status', example='1'),
  }(name='Result'),
}

model EntElementVerifyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EntElementVerifyResponseBody(name='body'),
}

/**
 * @summary 企业要素核验
 *
 * @param request EntElementVerifyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return EntElementVerifyResponse
 */
async function entElementVerifyWithOptions(request: EntElementVerifyRequest, runtime: $RuntimeOptions): EntElementVerifyResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.entName)) {
    query['EntName'] = request.entName;
  }
  if (!$isNull(request.infoVerifyType)) {
    query['InfoVerifyType'] = request.infoVerifyType;
  }
  if (!$isNull(request.legalPersonCertNo)) {
    query['LegalPersonCertNo'] = request.legalPersonCertNo;
  }
  if (!$isNull(request.legalPersonName)) {
    query['LegalPersonName'] = request.legalPersonName;
  }
  if (!$isNull(request.licenseNo)) {
    query['LicenseNo'] = request.licenseNo;
  }
  if (!$isNull(request.merchantBizId)) {
    query['MerchantBizId'] = request.merchantBizId;
  }
  if (!$isNull(request.merchantUserId)) {
    query['MerchantUserId'] = request.merchantUserId;
  }
  if (!$isNull(request.sceneCode)) {
    query['SceneCode'] = request.sceneCode;
  }
  if (!$isNull(request.userAuthorization)) {
    query['UserAuthorization'] = request.userAuthorization;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'EntElementVerify',
    version = '2022-11-25',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 企业要素核验
 *
 * @param request EntElementVerifyRequest
 * @return EntElementVerifyResponse
 */
async function entElementVerify(request: EntElementVerifyRequest): EntElementVerifyResponse {
  var runtime = new $RuntimeOptions{};
  return entElementVerifyWithOptions(request, runtime);
}

model EntElementVerifyV2Request {
  entName?: string(name='EntName', description='This parameter is required.'),
  infoVerifyType?: string(name='InfoVerifyType', description='This parameter is required.', example='ENT_2META'),
  legalPersonCertNo?: string(name='LegalPersonCertNo', example='1******************9'),
  legalPersonName?: string(name='LegalPersonName'),
  licenseNo?: string(name='LicenseNo', description='This parameter is required.', example='91330106673959****'),
  merchantBizId?: string(name='MerchantBizId', description='This parameter is required.', example='e0c34a77f5ac40a5aa5e6ed20c35****'),
  merchantUserId?: string(name='MerchantUserId', description='This parameter is required.', example='mch7x9a2b4c8d3e5f6g1h2i3j4k5****'),
  sceneCode?: string(name='SceneCode', description='This parameter is required.', example='1000000006'),
  userAuthorization?: string(name='UserAuthorization', description='This parameter is required.', example='1'),
}

model EntElementVerifyV2ResponseBody = {
  code?: string(name='Code', example='Success'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='473469C7***B-A3DC0DE3C83E'),
  result?: {
    bizCode?: string(name='BizCode', example='1'),
    openTime?: string(name='OpenTime', example='2018-09-25/9999-09-09'),
    reasonDetail?: string(name='ReasonDetail', example='LegalPersonNameFlag,LegalPersonCertNoFlag'),
    status?: string(name='Status', example='1'),
  }(name='Result'),
}

model EntElementVerifyV2Response = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EntElementVerifyV2ResponseBody(name='body'),
}

/**
 * @summary 企业要素验证V2
 *
 * @param request EntElementVerifyV2Request
 * @param runtime runtime options for this request RuntimeOptions
 * @return EntElementVerifyV2Response
 */
async function entElementVerifyV2WithOptions(request: EntElementVerifyV2Request, runtime: $RuntimeOptions): EntElementVerifyV2Response {
  request.validate();
  var query = {};
  if (!$isNull(request.entName)) {
    query['EntName'] = request.entName;
  }
  if (!$isNull(request.infoVerifyType)) {
    query['InfoVerifyType'] = request.infoVerifyType;
  }
  if (!$isNull(request.legalPersonCertNo)) {
    query['LegalPersonCertNo'] = request.legalPersonCertNo;
  }
  if (!$isNull(request.legalPersonName)) {
    query['LegalPersonName'] = request.legalPersonName;
  }
  if (!$isNull(request.licenseNo)) {
    query['LicenseNo'] = request.licenseNo;
  }
  if (!$isNull(request.merchantBizId)) {
    query['MerchantBizId'] = request.merchantBizId;
  }
  if (!$isNull(request.merchantUserId)) {
    query['MerchantUserId'] = request.merchantUserId;
  }
  if (!$isNull(request.sceneCode)) {
    query['SceneCode'] = request.sceneCode;
  }
  if (!$isNull(request.userAuthorization)) {
    query['UserAuthorization'] = request.userAuthorization;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'EntElementVerifyV2',
    version = '2022-11-25',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 企业要素验证V2
 *
 * @param request EntElementVerifyV2Request
 * @return EntElementVerifyV2Response
 */
async function entElementVerifyV2(request: EntElementVerifyV2Request): EntElementVerifyV2Response {
  var runtime = new $RuntimeOptions{};
  return entElementVerifyV2WithOptions(request, runtime);
}

model EntRiskQueryRequest {
  merchantBizId?: string(name='MerchantBizId', example='32198****193000'),
  merchantUserId?: string(name='MerchantUserId'),
  paramType?: string(name='ParamType', example='00'),
  paramValue?: string(name='ParamValue', example='91330106673959****'),
  sceneCode?: string(name='SceneCode', example='1000000086'),
  userAuthorization?: string(name='UserAuthorization', example='1'),
}

model EntRiskQueryResponseBody = {
  code?: string(name='Code', example='200'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='8FC3D6AC-9FED-4311-8DA7-C4BF47D9F260'),
  result?: {
    bizCode?: string(name='BizCode', example='1'),
    riskList?: [ 
      {
        creditCode?: string(name='CreditCode', example='92500112MA5UHU****'),
        entName?: string(name='EntName'),
        listedDate?: string(name='ListedDate', example='2023-02-03'),
        listedReason?: string(name='ListedReason'),
        operationOrg?: string(name='OperationOrg'),
        regNo?: string(name='RegNo', example='50011260996****'),
        removedDate?: string(name='RemovedDate', example='2023-02-06'),
        removedOrg?: string(name='RemovedOrg'),
        removedReason?: string(name='RemovedReason'),
      }
    ](name='RiskList'),
    status?: string(name='Status', example='1'),
  }(name='Result'),
}

model EntRiskQueryResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EntRiskQueryResponseBody(name='body'),
}

/**
 * @summary 企业经营异常查询
 *
 * @param request EntRiskQueryRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return EntRiskQueryResponse
 */
async function entRiskQueryWithOptions(request: EntRiskQueryRequest, runtime: $RuntimeOptions): EntRiskQueryResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.merchantBizId)) {
    query['MerchantBizId'] = request.merchantBizId;
  }
  if (!$isNull(request.merchantUserId)) {
    query['MerchantUserId'] = request.merchantUserId;
  }
  if (!$isNull(request.paramType)) {
    query['ParamType'] = request.paramType;
  }
  if (!$isNull(request.paramValue)) {
    query['ParamValue'] = request.paramValue;
  }
  if (!$isNull(request.sceneCode)) {
    query['SceneCode'] = request.sceneCode;
  }
  if (!$isNull(request.userAuthorization)) {
    query['UserAuthorization'] = request.userAuthorization;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'EntRiskQuery',
    version = '2022-11-25',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 企业经营异常查询
 *
 * @param request EntRiskQueryRequest
 * @return EntRiskQueryResponse
 */
async function entRiskQuery(request: EntRiskQueryRequest): EntRiskQueryResponse {
  var runtime = new $RuntimeOptions{};
  return entRiskQueryWithOptions(request, runtime);
}

model EntVerifyRequest {
  accountNo?: string(name='AccountNo', example='321324***38293'),
  entName?: string(name='EntName'),
  infoVerifyType?: string(name='InfoVerifyType'),
  legalPersonCertNo?: string(name='LegalPersonCertNo', example='370105*****3892'),
  legalPersonMobile?: string(name='LegalPersonMobile', example='1300***53'),
  legalPersonName?: string(name='LegalPersonName'),
  licenseNo?: string(name='LicenseNo', example='32132***328932'),
  merchantBizId?: string(name='MerchantBizId'),
  merchantUserId?: string(name='MerchantUserId'),
  riskModelVersion?: string(name='RiskModelVersion', example='BASIC'),
  riskVerifyType?: string(name='RiskVerifyType'),
  sceneCode?: string(name='SceneCode', example='withdraw'),
  userAuthorization?: string(name='UserAuthorization', example='1'),
}

model EntVerifyResponseBody = {
  code?: string(name='Code', example='Success'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request', example='473469C7-A***B-A3DC0DE3C83E'),
  result?: {
    riskVerifyResult?: {
      found?: boolean(name='Found', example='true'),
      modelResults?: [ 
        {
          modelName?: string(name='ModelName', example='model_1'),
          result?: string(name='Result'),
        }
      ](name='ModelResults'),
    }(name='RiskVerifyResult'),
  }(name='Result'),
}

model EntVerifyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EntVerifyResponseBody(name='body'),
}

/**
 * @summary 企业认证
 *
 * @param request EntVerifyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return EntVerifyResponse
 */
async function entVerifyWithOptions(request: EntVerifyRequest, runtime: $RuntimeOptions): EntVerifyResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.accountNo)) {
    query['AccountNo'] = request.accountNo;
  }
  if (!$isNull(request.entName)) {
    query['EntName'] = request.entName;
  }
  if (!$isNull(request.infoVerifyType)) {
    query['InfoVerifyType'] = request.infoVerifyType;
  }
  if (!$isNull(request.legalPersonCertNo)) {
    query['LegalPersonCertNo'] = request.legalPersonCertNo;
  }
  if (!$isNull(request.legalPersonMobile)) {
    query['LegalPersonMobile'] = request.legalPersonMobile;
  }
  if (!$isNull(request.legalPersonName)) {
    query['LegalPersonName'] = request.legalPersonName;
  }
  if (!$isNull(request.licenseNo)) {
    query['LicenseNo'] = request.licenseNo;
  }
  if (!$isNull(request.merchantBizId)) {
    query['MerchantBizId'] = request.merchantBizId;
  }
  if (!$isNull(request.merchantUserId)) {
    query['MerchantUserId'] = request.merchantUserId;
  }
  if (!$isNull(request.riskModelVersion)) {
    query['RiskModelVersion'] = request.riskModelVersion;
  }
  if (!$isNull(request.riskVerifyType)) {
    query['RiskVerifyType'] = request.riskVerifyType;
  }
  if (!$isNull(request.sceneCode)) {
    query['SceneCode'] = request.sceneCode;
  }
  if (!$isNull(request.userAuthorization)) {
    query['UserAuthorization'] = request.userAuthorization;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'EntVerify',
    version = '2022-11-25',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 企业认证
 *
 * @param request EntVerifyRequest
 * @return EntVerifyResponse
 */
async function entVerify(request: EntVerifyRequest): EntVerifyResponse {
  var runtime = new $RuntimeOptions{};
  return entVerifyWithOptions(request, runtime);
}

